package de.mmis.core.base.abstracttree;

/**
 * Exception, that is thrown, when an error occurred while parsing {@link Tree}s
 * 
 * @author Christian Koch
 */
public class TreeParserException extends Exception {
	private final boolean unexpectedEOF;
	private final boolean noDataRead;

	/**
	 * creates new {@link TreeParserException} with given message string
	 * 
	 * @param string
	 *            exception message string
	 */
	public TreeParserException(String string) {
		this(string, false, false);
	}

	/**
	 * creates new {@link TreeParserException} with given message string
	 * 
	 * @param string
	 *            exception message string
	 * @param noDataRead
	 *            specifies, whether the exception is thrown because end of
	 *            input stream reached unexpectedly
	 */
	public TreeParserException(String string, boolean unexpectedEOF,
			boolean noDataRead) {
		super(string);
		this.unexpectedEOF = unexpectedEOF;
		this.noDataRead = noDataRead;
	}

	/**
	 * @return true, if this {@link TreeParserException} is throws because end
	 *         of input stream reached unexpectedly. This information can be
	 *         used to determine whether the underlying stream has to be closed.
	 */
	public boolean cleanEndOfStreamOccurred() {
		return this.noDataRead && this.unexpectedEOF;
	}

	/**
	 * @return true, if this {@link TreeParserException} is throws because end
	 *         of input stream reached unexpectedly. This information can be
	 *         used to determine whether the underlying stream has to be closed.
	 */
	public boolean unexpectedEndOfStreamOccurred() {
		return this.unexpectedEOF;
	}

	private static final long serialVersionUID = 4576980932359126401L;
}